<p>This rule raises an issue when bitwise operators like <code>| 0</code>, <code>~~</code>, <code>&gt;&gt; 0</code>, <code>&lt;&lt; 0</code>, or
<code>^ 0</code> are used to truncate numbers instead of using <code>Math.trunc()</code>.</p>
<h2>Why is this an issue?</h2>
<p>Using bitwise operators to truncate numbers is a common JavaScript "hack" that appears in many codebases. While these operations can truncate
decimal numbers to integers, they create several problems:</p>
<p><strong>Clarity and Intent</strong>: Bitwise operations like <code>x | 0</code> or <code>~~x</code> are not immediately clear to most developers.
The intent to truncate a number is hidden behind cryptic syntax that requires specific JavaScript knowledge to understand.</p>
<p><strong>Reliability Issues</strong>: These bitwise operations only work correctly for numbers within the 32-bit signed integer range
(-2,147,483,648 to 2,147,483,647). For numbers outside this range, the results can be unexpected and incorrect. For example, <code>9999999999 |
0</code> returns <code>1410065407</code> instead of <code>9999999999</code>.</p>
<p><strong>Maintenance Burden</strong>: Code using these patterns is harder to maintain because:</p>
<ul>
  <li> New team members may not understand the intent </li>
  <li> The limitations are not obvious from the code </li>
  <li> Debugging issues with large numbers becomes more difficult </li>
</ul>
<p><strong>Modern Alternative</strong>: <code>Math.trunc()</code> was introduced in ES2015 specifically for this purpose. It clearly expresses the
intent to truncate a number and works correctly for all JavaScript numbers, including those outside the 32-bit integer range.</p>
<h3>What is the potential impact?</h3>
<p>Using bitwise operators for number truncation can lead to incorrect results when working with large numbers, making applications unreliable. The
unclear syntax also reduces code maintainability and increases the likelihood of bugs during development and maintenance.</p>
<h3>How to fix?</h3>
<p>Replace bitwise OR with zero with <code>Math.trunc()</code> to clearly express the intent and ensure correct behavior for all numbers.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
const result = value | 0; // Noncompliant
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
const result = Math.trunc(value);
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-math-trunc.md">prefer-math-trunc</a> </li>
  <li> MDN - Math.trunc() - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc">Official
  documentation for the Math.trunc() method</a> </li>
  <li> MDN - Bitwise operators - <a
  href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators#bitwise_shift_operators">Documentation about JavaScript bitwise
  operators and their behavior</a> </li>
</ul>
